// =================================================================================================
//
//	CopyEngine Framework
//	Copyright 2012 Eran. All Rights Reserved.
//
//	This program is free software. You can redistribute and/or modify it
//	in accordance with the terms of the accompanying license agreement.
//
// =================================================================================================

package gui.fileSetting
{
    import com.bit101.components.PushButton;

    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.filesystem.File;
    import flash.text.TextField;

    import manger.LogicManger;

    import utils.ConfirmBox;
    import utils.GUIUtils;

    public class FileSettingPanel
    {
        private var mFileSettingPanelMc:MovieClip;

        private var mLogicManger:LogicManger;

        private var mOpenButton:PushButton;
        private var mSaveButton:PushButton;

        private var mSavePathTF:TextField;

        private var mCurrentFile:File;

        public function FileSettingPanel()
        {
        }

        //==================================
        //== Initialize & Dispose
        //==================================

        public function initialize(_fileSettingPanelMc:MovieClip, _logicManger:LogicManger):void
        {
            mFileSettingPanelMc = _fileSettingPanelMc;
            mLogicManger = _logicManger;

            mOpenButton = new PushButton(null, 0, 0, "Open", onClickOpenButton);
            GUIUtils.replaceTargetWithPH(mOpenButton, mFileSettingPanelMc["openBtnPH"]);

            mSaveButton = new PushButton(null, 0, 0, "Save", onClickSaveButton);
            GUIUtils.replaceTargetWithPH(mSaveButton, mFileSettingPanelMc["saveBtnPH"]);

            mSavePathTF = mFileSettingPanelMc["savePathTF"];
            mSavePathTF.visible = false;
        }

        //==================================
        //== Public Function
        //==================================

        public function refresh(_currentFile:File):void
        {
            mCurrentFile = _currentFile;
            if (mCurrentFile != null)
            {
                mSavePathTF.visible = true;
                mSavePathTF.text = mCurrentFile.nativePath;
            }
            else
            {
                mSavePathTF.visible = false;
            }
        }


        //==================================
        //== Private Function
        //==================================

        //=================
        //==Event Handle
        //=================

        private function onClickOpenButton(e:MouseEvent):void
        {
            ConfirmBox.instance.ask("打开新的会导致当前丢失\n是否继续?", onConfirmOpenNewFile);
        }

        private function onClickSaveButton(e:MouseEvent):void
        {
            mLogicManger.onClickSaveFile();
        }

        //================
        //==Event Confirm
        //================

        private function onConfirmOpenNewFile():void
        {
            mLogicManger.onClickOpenNewFile();
        }


    }
}
